package com.itheima.chapter11.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds =new DatagramSocket(10086);
        byte[] bys =new byte[1024];
        DatagramPacket dp =new DatagramPacket(bys, bys.length);
        ds.receive(dp);
        byte[] data = dp.getData();
        int length = dp.getLength();
        String dateString = new String(bys, 0, length);
        String hostName = dp.getAddress().getHostName();
        System.out.println("接受到"+hostName+"发送的数据是"+dateString);
        ds.close();
    }
}
